package com.cqeec.service.imp;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JOptionPane;
 
import com.cqeec.dao.StudentDao; 
import com.cqeec.dao.imp.StudentDaoImp; 
import com.cqeec.domain.Student;
import com.cqeec.service.StudentService;

/***
 * 学生业务处理
 * 
 * @author 11787
 *
 */
public class StudentServiceImpl implements StudentService {
	/**
	 */
	@Override
	public Student findStudentByID(Connection conn, Student student) {

		StudentDao dao = new StudentDaoImp();

		Student user = dao.findStudentByID(conn, student.getStudentNum());

		if (user == null) {
			JOptionPane.showMessageDialog(null, "没有该学生", "提示", JOptionPane.ERROR_MESSAGE);
			return null;
		}
		if (user.getStudentPwd().trim().equals(student.getStudentPwd().trim())) {
			return user;
		}
		return user;

	}

	/**
	 * 添加学生
	 */
	@Override
	public int addStudents(Connection com, Student student) {
		StudentDao dao = new StudentDaoImp();
		int rs = dao.addStudentByID(com, student);

		if (rs == 0) {
			JOptionPane.showMessageDialog(null, "添加失败", "提示", JOptionPane.ERROR_MESSAGE);
			return 0;
		}

		return rs;
	}

	/**
	 * 查询考勤
	 */
	@Override
	public ResultSet getallCallRoll(Connection conn) {
		StudentDao dao = new StudentDaoImp();
		ResultSet rs = dao.getallCallRollImpl(conn);
		if (rs == null) {
			JOptionPane.showMessageDialog(null, "你没有旷课记录", "提示", JOptionPane.ERROR_MESSAGE);
		}

		return rs;
	}

	@Override
	public void upateStudentByStudentName(Connection connection, Student student) throws SQLException {
		// TODO Auto-generated method stub
		StudentDao dao = new StudentDaoImp();
		dao.upateStudentByStudentName(connection,student);
	}

}
